package divinity.objects
{
	import flash.events.Event;
	import flash.geom.Point;
	
	import divinity.utils.*;

	public class ActiveObject extends WorldObject
	{
		protected var _newx:Number=0;
		protected var _newy:Number=0;
		protected var _g:Number=0;
		protected var _w:Number=0;
		private var _altitude:int=0;
	
		private var _speedFactor:Number=1;
		public function ActiveObject()
		{
			super();
			
		}
		override public function init(e:Event)
		{
			super.init(e);
			
			
		}
		override protected function moving():void
		{
			moveMechancis(_elapsed);			
		}
		override protected function makeMove():void
		{
			if(alive)
			{
				
				x=_newx;
				y=_newy;
				setShadow();
				
			}
		}
		protected function moveMechancis(deltaTime:Number):Point
		{
			_newx=x+vx*(xspeed*_speedFactor)*deltaTime;
			_newy=y+vy*(yspeed*_speedFactor)*deltaTime;
			/*
			*	APPLY GRAVITY
			*/
			if(mass>0)
			{
				
				_newy+=_g*deltaTime;
				_g+=(mass/1000);
				if(_g>(mass*world.gravity))
				{
					_g=(mass*world.gravity)
				}
			}	
			/*
			*	APPLY WIND
			*/
			
				_w+=(world.wind.speed/1000)*deltaTime;;
				if(_w>world.wind.speed)				
				{
					_w=world.wind.speed;
				}
				var toApply:Number=(_w-mass)/1000;
				toApply=(toApply<0)?(0):(toApply);
				trace(this,toApply);
				_newx+=world.wind.vx*toApply*deltaTime;
				_newy+=world.wind.vy*toApply*deltaTime;
				
			var newpos:Point=new Point(_newx,_newy);
			return newpos;
		}
		//
		//
		protected function setShadow()
		{
			Filters.addFilters(img,"DropShadowFilter,quality:3,angle:"+world.sunAngle+",distance:"+((_altitude/255)*40)+",alpha:"+world.sunStrength);
		}
		public function get speedFactor():Number
		{
			return _speedFactor;
		}
		public function set speedFactor(fac:Number):void
		{
			_speedFactor=fac;
		}

		public function get altitude():int
		{
			return _altitude;
		}

		public function set altitude(value:int):void
		{
			_altitude = value;
			
		}

		

		
	}
}